--- title: Interactive plotting keywords: fastai sidebar: home_sidebar summary: "The amazing possibilities of ipywidgets" description: "The amazing possibilities of ipywidgets" nb_path: "notebooks/91_interactive-plotting.ipynb" ---
{% raw %}
{% endraw %}

The whole point of doing all this is of course to be able to communicate the results of data processing in as rich a manner as possible.

We have saved the calculated element maps in our datastack file. First create a standard static plot.

{% raw %}
from maxrf4u import multi_plot
{% endraw %} {% raw %}
ds = DataStack('RP-T-1898-A-3689.datastack')

elements = ds.read('nmf_elements')
element_maps = ds.read('nmf_elementmaps')
element_maps_histeq = [ske.equalize_hist(m) for m in element_maps]

multi_plot(*element_maps_histeq, titles=elements);
{% endraw %}

Not sure if this plot can also be exported...

So let's see if we can plot them interactively. Let's first try the base64 approach.

{% raw %}
from maxrf4u import img_to_url
{% endraw %} {% raw %}
from ipyleaflet import Map, ImageOverlay 
{% endraw %} {% raw %}
import json 

from IPython.display import display
from ipywidgets import Layout, HBox, VBox, GridBox, jslink, HTML
from ipyleaflet import (Map, projections, ImageOverlay, Rectangle, ZoomControl, FullScreenControl, 
                        DrawControl, WKTLayer, Popup)
from ipywidgets.embed import embed_minimal_html, embed_data 
{% endraw %} {% raw %}
url, shape = img_to_url(element_maps_histeq[0], max_width=500) # first trying small 

layout = Layout(width='300px', height='300px')
m = Map(center=[50, 50], zoom=2, crs=projections['Simple'], layout=layout, 
            scroll_wheel_zoom=True, interpolation='nearest')
imo = ImageOverlay(url=url, bounds=[[0, 0], [100, 100]], 
                   attribution='<a href="https://openheritagescience.org" target="_blank">RP-T-1898-A-3689</a> Madonna with child')
fsc = FullScreenControl()

m.add(imo)
m.add(fsc)
m.remove(m.layers[0]) # hack to remove world map 

m
{% endraw %}